package com.cug.nageoffer.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cug.nageoffer.model.entity.OfflineResume;
import com.cug.nageoffer.model.vo.Result;
import com.cug.nageoffer.model.vo.ResultCodeEnum;
import com.cug.nageoffer.user.mapper.OfflineResumeMapper;
import com.cug.nageoffer.user.service.OfflineResumeService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OfflineResumeServiceImpl extends ServiceImpl<OfflineResumeMapper, OfflineResume> implements OfflineResumeService {
    @Override
    public void upload(String filePath) {
        // TODO 用户id从thread_local中获取
        OfflineResume offlineResume = OfflineResume.builder().userId(2).url(filePath).build();
        save(offlineResume);
    }

    @Override
    public Result<List<OfflineResume>> search(Long userId) {
        List<OfflineResume> offlineResumeList = query().eq("user_id", userId).list();
        if(offlineResumeList.isEmpty()){
            return Result.build(null, ResultCodeEnum.SUCCESS);
        }
        return Result.build(offlineResumeList,ResultCodeEnum.SUCCESS);
    }

    @Override
    public Result<String> delete(Integer id) {
        try {
            delete(id);
        }
        catch (Throwable e){
            log.error("删除失败");
            return Result.build(null,ResultCodeEnum.RESUME_NOT_EXIST);
        }
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
